package com.oba.king.sysmanager;

import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import com.oba.base.dao.DBDataModel;
import com.oba.base.service.BaseBean;

public class UserGroupBean extends BaseBean<UserGroup, UserGroupService> {

	private DBDataModel userGroupList = DBDataModel.create();
	private UserGroup userGroup;
	private List<SelectItem> deptList;
	private Dept dept;
	private String userGroupName;
	private boolean showUserGroup;

	@Override
	public String doFind() {
		userGroupList.find(getService().getDao().buildByCondition(dept, userGroupName));
		return null;
	}

	@Override
	public void init() {
		showUserGroup = false;
		userGroup = new UserGroup();
		userGroupList.find(getService().getDao().buildAll());
		deptList = new ArrayList<SelectItem>();
		deptList.add(new SelectItem(null,"全部"));
		for (Dept d : getService().getDao().findAllDept()) {
			deptList.add(new SelectItem(d, d.getName()));
		}
	}

	public void doAddRow() {
		userGroup = new UserGroup();
		userGroup.setNewBo(true);
		showUserGroup = true;
	}

	public void doEditRow() {
		if (userGroupList.isRowAvailable()) {
			userGroup = (UserGroup) userGroupList.getRowData();
			showUserGroup = true;
		}
	}

	public void doDeleteRow() {
		if (userGroupList.isRowAvailable()) {
			userGroup = (UserGroup) userGroupList.getRowData();
			getService().del(userGroup);
			doFind();
		}
	}

	public void doSaveRow() {
		getService().save(userGroup);
		showUserGroup = false;
		doFind();
	}

	public void closeShowUserGroup() {
		showUserGroup = false;
	}

	public DBDataModel getUserGroupList() {
		return userGroupList;
	}

	public void setUserGroupList(DBDataModel userGroupList) {
		this.userGroupList = userGroupList;
	}

	public UserGroup getUserGroup() {
		return userGroup;
	}

	public void setUserGroup(UserGroup userGroup) {
		this.userGroup = userGroup;
	}

	public List<SelectItem> getDeptList() {
		return deptList;
	}

	public void setDeptList(List<SelectItem> deptList) {
		this.deptList = deptList;
	}

	public Dept getDept() {
		return dept;
	}

	public void setDept(Dept dept) {
		this.dept = dept;
	}

	public String getUserGroupName() {
		return userGroupName;
	}

	public void setUserGroupName(String userGroupName) {
		this.userGroupName = userGroupName;
	}

	public boolean isShowUserGroup() {
		return showUserGroup;
	}

	public void setShowUserGroup(boolean showUserGroup) {
		this.showUserGroup = showUserGroup;
	}

}
